/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package remoteEntity;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author viktor
 */
@Entity
@Table(name = "download")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Download.findAll", query = "SELECT d FROM Download d"),
    @NamedQuery(name = "Download.findById", query = "SELECT d FROM Download d WHERE d.id = :id"),
    @NamedQuery(name = "Download.findByTimestamp", query = "SELECT d FROM Download d WHERE d.timestamp = :timestamp"),
    @NamedQuery(name = "Download.findByFiledescriptionId", query = "SELECT d FROM Download d WHERE d.filedescriptionId = :filedescriptionId"),
    @NamedQuery(name = "Download.findByUserId", query = "SELECT d FROM Download d WHERE d.userId = :userId ORDER BY d.timestamp DESC")})
public class Download implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @NotNull
    @Column(name = "id")
    private Integer id;
    @Column(name = "timestamp")
    @Temporal(TemporalType.TIMESTAMP)
    private Date timestamp;
    @Basic(optional = false)
    @NotNull
    @Column(name = "filedescription_id")
    private int filedescriptionId;
    @JoinColumn(name="filedescription_id", insertable=false, updatable=false, nullable=false)
    @OneToOne(optional = false, fetch=FetchType.LAZY)
    private Filedescription filedescription;
    @Basic(optional = false)
    @NotNull
    @Column(name = "user_id")
    private int userId;

    public Download() {
    }

    public Download(Integer id) {
        this.id = id;
    }

    public Download(Integer id, int filedescriptionId, int userId) {
        this.id = id;
        this.filedescriptionId = filedescriptionId;
        this.userId = userId;
    }

    public Filedescription getFiledescription() {
        return filedescription;
    }

    public void setFiledescription(Filedescription filedescription) {
        this.filedescription = filedescription;
    }
    
    

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Date getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(Date timestamp) {
        this.timestamp = timestamp;
    }

    public int getFiledescriptionId() {
        return filedescriptionId;
    }

    public void setFiledescriptionId(int filedescriptionId) {
        this.filedescriptionId = filedescriptionId;
    }

    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Download)) {
            return false;
        }
        Download other = (Download) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.Download[ id=" + id + " ]";
    }
    
}
